package utils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/*
 * 
 * This Class is used for send sms with the help of getHelper class
 */
public class ApiSendMessage {

	static long TimeStamp;
	static String md5Part;
	static String codestr;
	static String result;
	static String url;

	public static long send(String msg, String mobileNum, int smsplatform) {
		/**
		 * 汗..这设计，恩我自己也看不下去了，有空再重构了
		 */
		if (smsplatform == 1) {
			return one(msg, mobileNum);
		} else if (smsplatform == 2) {
			return two(msg, mobileNum);
		} else if (smsplatform == 3) {
			return three(msg, mobileNum);
		} else if (smsplatform == 4) {
			// 安杰
			return four(msg, mobileNum);
		} else if (smsplatform == 5) {
			return five(msg, mobileNum);
		} else if (smsplatform == 6) {
			return six(msg, mobileNum);
		} else if (smsplatform == 7) {
			return seven(msg, mobileNum);
		} else if (smsplatform == 8) {
			return eight(msg, mobileNum);
		} else if (smsplatform == 9) {
			return nine(msg, mobileNum);
		} else if (smsplatform == 10) {
			return ten(msg, mobileNum);
		}
		return one(msg, mobileNum);

	}

	public static long one(String msg, String mobileNum) {

		try {
			codestr = URLEncoder.encode(msg, "GBK");

			TimeStamp = System.currentTimeMillis() / 1000; // the unit is second

			md5Part = MD5Helper.getMD5Str("123456_" + TimeStamp + "_topsky");

			url = "http://115.182.33.133/houtai/sms.php?" + "cpid=4617&"
					+ "password=" + md5Part + "&channelid=3028&" + "tele="
					+ mobileNum + "&" + "msg=" + codestr + "&" + "timestamp="
					+ TimeStamp;

			result = GetHelper.doHttpGet(url);
			// result="success:322232";
			System.out.println("result: " + result);
			if (String.valueOf(result.charAt(0)).equals("s")) {
				return Long.parseLong(result.substring(result.indexOf(":") + 1)
						.trim());
			} else {
				return -1;
			}

		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return -1;
		}

	}

	public static long two(String msg, String mobileNum) {
		return vcomcn.sendSms(msg, mobileNum);
	}

	public static long three(String msg, String mobileNum) {
		try {
			return hl95.send(msg, mobileNum);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}

	public static long four(String msg, String mobileNum) {
		try {
			return AnJieSMS.send(msg, mobileNum);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}

	public static long five(String msg, String mobileNum) {
		return vcomcn.send720Sms(msg, mobileNum);
	}

	public static long six(String msg, String mobileNum) {

		try {
			codestr = URLEncoder.encode(msg, "GBK");

			TimeStamp = System.currentTimeMillis() / 1000; // the unit is second

			md5Part = MD5Helper.getMD5Str("hantianxia654321_" + TimeStamp + "_topsky");

			url = "http://115.182.33.133/houtai/sms.php?" + "cpid=9604&"
					+ "password=" + md5Part + "&channelid=12635&" + "tele="
					+ mobileNum + "&" + "msg=" + codestr + "&" + "timestamp="
					+ TimeStamp;

			result = GetHelper.doHttpGet(url);
			// result="success:322232";
			System.out.println("result: " + result);
			if (String.valueOf(result.charAt(0)).equals("s")) {
				return Long.parseLong(result.substring(result.indexOf(":") + 1)
						.trim());
			} else {
				return -1;
			}

		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return -1;
		}

	}
	
	public static long seven(String msg, String mobileNum) {

		try {
			codestr = URLEncoder.encode(msg, "GBK");

			TimeStamp = System.currentTimeMillis() / 1000; // the unit is second

			md5Part = MD5Helper.getMD5Str("kaixuan409409_" + TimeStamp + "_topsky");

			url = "http://admin.sms9.net/houtai/sms.php?" + "cpid=10051&"
					+ "password=" + md5Part + "&channelid=12635&" + "tele="
					+ mobileNum + "&" + "msg=" + codestr + "&" + "timestamp="
					+ TimeStamp;

			result = GetHelper.doHttpGet(url);
			// result="success:322232";
			System.out.println("result: " + result);
			if (String.valueOf(result.charAt(0)).equals("s")) {
				return Long.parseLong(result.substring(result.indexOf(":") + 1)
						.trim());
			} else {
				return -1;
			}

		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return -1;
		}

	}
	
	public static long eight(String msg, String mobileNum) {
		return YiYouSMS.sendMsg(msg, mobileNum);
	}
	
	public static long nine(String msg, String mobileNum) {
		return vcomcn.sendYYSms(msg, mobileNum);
	}
	
	public static long ten(String msg, String mobileNum) {
		try {
			return YiXinTongSMS.send(msg, mobileNum);
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	public static void main(String[] args) {
		System.out.println(ten(
				"您的顺丰快递包裹fg12343d56456234已存入交通厅网点邮宝智能快递箱一号机1号箱,取件码:123456.服务号码:18144000235.(以本条短信为准)",
				"13559455537"));
	}
}
